package com.boot.seven.rabbitmq.header;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lkz
 * @Title: HeaderRabbitConfig
 * @Description: 头部交换机 使用比较少
 * @Date: 2023/10/16 9:47
 */
@Configuration
public class HeaderRabbitConfig {

    /**
     * 声明交换机
     */
    @Bean
    public HeadersExchange headersExchange(){
        return ExchangeBuilder.headersExchange("headersExchange").durable(true).build();
    }


    /**
     * 声明队列
     */
    @Bean
    public Queue headerQueue(){
        return QueueBuilder.durable("headerQueue").build();
    }

    @Bean
    public Queue headerQueueB(){
        return QueueBuilder.durable("headerQueueB").build();
    }


    /**
     * 队列绑定交换机
     */
    @Bean
    public Binding headerBing(HeadersExchange headersExchange,Queue headerQueue){
        Map<String, Object> headerValues=new HashMap<>();
        headerValues.put("type","m");
        headerValues.put("status",1);
        return BindingBuilder.bind(headerQueue).to(headersExchange).whereAll(headerValues).match();
    }


    @Bean
    public Binding bindingB(HeadersExchange headersExchange,Queue headerQueueB){
        Map<String, Object> headerValues=new HashMap<>();
        headerValues.put("type","s");
        headerValues.put("status",0);
        return BindingBuilder.bind(headerQueueB).to(headersExchange).whereAll(headerValues).match();
    }


}
